home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Miscellaneous / ival / error.c < prev    next >
Text File  |  1987-04-24  |  3KB  |  117 lines

  1. /*
  2.  * error.c - error notification routines
  3.  */
  4.  
  5. #include <quickdraw.h>
  6. #include <memory.h>
  7. #include <dialog.h>
  8. #include <toolutil.h>
  9. #include <syserr.h>
  10. #include <packages.h>
  11.  
  12. #define ALTBOMB        401    /* Resource ID of our generic alert    */
  13. #define DISKSTRS    401    /* System error strings            */
  14. #define PROGSTRS    402    /* Program-specific error strings    */
  15.  
  16. static short errstr[] = {    /* string # to error-number mapping    */
  17.   dirFulErr, dskFulErr, nsvErr, ioErr, bdNamErr,
  18.   fnOpnErr, eofErr, posErr, mFulErr, tmfoErr,
  19.   fnfErr, wPrErr, fLckdErr, vLckdErr, fBsyErr,
  20.   dupFNErr, opWrErr, paramErr, rfNumErr, gfpErr,
  21.   volOffLinErr, permErr, volOnLinErr, nsDrvErr, noMacDskErr,
  22.   extFSErr, fsRnErr, badMDBErr, wrPermErr, memFullErr
  23. };
  24.  
  25. static char msg[256];    /* buffer for any text to put in an error alert    */
  26.  
  27. /*
  28.  * diskerr() - given a system error number, notify the user of the error.
  29.  */
  30.  
  31. diskerr(err)
  32. OSErr err;
  33. {
  34.     short sidx;        /* index of the string to say        */
  35.  
  36.     /*
  37.      * find the index of the errstr[] entry that has the given error code,
  38.      * Then use that index as a Resource string number to fetch and print.
  39.      */
  40.  
  41.     for (sidx = 1; sidx <= sizeof(errstr) / sizeof(errstr[0]); ++sidx) {
  42.     if (errstr[sidx - 1] == err) break;
  43.     }
  44.     if (sidx <= sizeof(errstr) / sizeof(errstr[0])) {
  45.     GetIndString(msg, DISKSTRS, sidx);
  46.     } else {
  47.     NumToString((long) err, msg);
  48.     }
  49.     ParamText(msg, (char *) 0, (char *) 0, (char *) 0);
  50.     (void) StopAlert(ALTBOMB, (ProcPtr) 0);
  51.     ResetAlrtStage();
  52. }
  53.  
  54. /*
  55.  * progstop(), prognote(), progcaution() - given a string ID from
  56.  *  the program's error strings,
  57.  *  print that string inside a Stop, Note, or Caution alert.
  58.  */
  59.  
  60. progstop(sidx) short sidx; { progmsg(sidx, stopIcon); }
  61. prognote(sidx) short sidx; { progmsg(sidx, noteIcon); }
  62. progcaution(sidx) short sidx; { progmsg(sidx, ctnIcon); }
  63.  
  64. /*
  65.  * progmsg() - server to progstop(), etc.
  66.  */
  67.  
  68. static
  69. progmsg(sidx, severity)
  70. short sidx;
  71. short severity;
  72. {
  73.     GetIndString(msg, PROGSTRS, sidx);
  74.     ParamText(msg, (char *) 0, (char *) 0, (char *) 0);
  75.     switch (severity) {
  76.     case stopIcon: (void) StopAlert(ALTBOMB, (ProcPtr) 0); break;
  77.     case noteIcon: (void) NoteAlert(ALTBOMB, (ProcPtr) 0); break;
  78.     case ctnIcon:  (void) CautionAlert(ALTBOMB, (ProcPtr) 0); break;
  79.     }
  80.     ResetAlrtStage();
  81. }
  82.  
  83. /*
  84.  * debugdlg() - (FOR DEBUG ONLY) display the given C string in an alert.
  85.  *  This routine allows a primitive form of debugging via sprintf()'s.
  86.  */
  87.  
  88. debugdlg(s)
  89. char *s;    /* C string */
  90. {
  91.     (void) strcpy(msg, s);
  92.     ctop(msg);
  93.     ParamText(msg, (char *) 0, (char *) 0, (char *) 0);
  94.     (void) StopAlert(ALTBOMB, (ProcPtr) 0);
  95. }
  96.  
  97. /*
  98.  * saydialog() - show the user the given dialog.
  99.  */
  100.  
  101. saydialog(dlgid)
  102. short dlgid;    /* Resource ID of the dialog to show */
  103. {
  104.     short itemhit;        
  105.     DialogPtr reportptr;
  106.  
  107.     /*
  108.      * Get the dialog; NIL => use heap storage; -1 => make dlg frontmost.
  109.      * Wait for some item to be selected (OK is the only one),
  110.      * then free up the memory and erase the dialog.
  111.      */
  112.  
  113.     reportptr = GetNewDialog(dlgid, (char *) 0, (long) -1);
  114.     ModalDialog((ProcPtr) 0, &itemhit);
  115.     DisposDialog(reportptr);
  116. }
  117.